package org.opens.guava.utilites.eventBus.events;

import com.google.common.eventbus.EventBus;
import org.junit.Test;
import org.opens.guava.utilites.eventBus.listeners.SimpleListener;

public class SimpleEventBusExample {

    /**
     * 功能:
     *      测试EventBus的时间监听.
     * 输出:
     *      12:15:11.171 [main] INFO org.opens.guava.utilites.eventBus.listeners.SimpleListener - 发生的 event: [simple event]
     * 说明:
     *      1. eventBus.register(new SimpleListener());是将自定义的监听器注册进当前的EventBus中:
     *          - 注册之后, 则注册的监听器中被@Subscribe修饰的方法在eventBus.post("simple event");指令执行时就会去判断参数类型, 决定是否执行方法(其实就是对监听器的方法进行参数匹配).
     *          - 但是好像只能匹配一个参数.
     */
    @Test
    public void test() {
        final EventBus eventBus = new EventBus();
        eventBus.register(new SimpleListener());
        eventBus.post("simple event");
    }

    @Test
    public void test2() {
        final EventBus eventBus = new EventBus();
        eventBus.register(new SimpleListener());
        eventBus.post("simple event");
    }

}
